var ClubStatisticsWindow = Window.extend({
    _ccsFileName: res.ClubStatisticsWindow_json,
    _clubId: null,
    _clubData: null,
    _currentSelectTab: null,
    _index: null,

    PanelClassName: {
        0: 'ClubMyRecordTab',   //我的战绩
        1: 'ClubRecordTab',     //亲友圈战绩
        2: 'ClubRankingTab',   //排行榜
        3: 'ClubDataOverviewTab',   //数据概况
        4: 'ClubUserDataTab',//大赢家数据
        5: 'ClubUserDataTab',//用户数据
    },

    initWindow: function (club_id,index) {
        this._clubId = club_id;
        this._index = index;
        if(index == 'shuju' ){
            ClubDataManager.ClubStatisticsLayerSelectTab = 3;
        }
        this._nodeList['bg_tongji'].setVisible(index == 'shuju')
        this._nodeList['bg_title'].setVisible(index == 'zhanji')
        for (var i = 0; i <= 5; i++) {
            this._nodeList['btnNode.btn' + i].index = i;
            this._nodeList['btnNode.btn' + i].viewTab = this.PanelClassName[i];
        }

        this._clubData = ClubDataManager.getClubData(this._clubId);
        this._initView();
        this._changeTab(ClubDataManager.ClubStatisticsLayerSelectTab);
    },

    _initClickListeners: function () {
        this._clickListeners = {
            'btn_close': '_clickClose',
        };
        for (var i = 0; i <= 5; i++) {
            this._clickListeners['btnNode.btn' + i] = '_clickTab';
        }
    },

    _clickTab: function (target) {
        this._changeTab(target.index);
    },

    /**
     * 初始化界面
     * 不同身份 显示的按钮不同
     * @private
     */
    _initView: function () {
        var isAdmin = ClubDataManager.isSelfAdministration(this._clubId, gameData.uid);
        var btnList = [];
        if (isAdmin) {
            if(this._index == 'zhanji'){
                btnList.push('btn0');
                btnList.push('btn1');
                this._nodeList['btnNode.btn3'].setVisible(false);
                this._nodeList['btnNode.btn4'].setVisible(false);
                this._nodeList['btnNode.btn5'].setVisible(false);
            }else {
                btnList.push('btn3');
                btnList.push('btn4');
                btnList.push('btn5');
                this._nodeList['btnNode.btn0'].setVisible(false);
                this._nodeList['btnNode.btn1'].setVisible(false);
            }

        } else {
            btnList.push('btn0');
            this._nodeList['btnNode.btn1'].setVisible(false);
            this._nodeList['btnNode.btn3'].setVisible(false);
            this._nodeList['btnNode.btn4'].setVisible(false);
            this._nodeList['btnNode.btn5'].setVisible(false);
        }
        this._nodeList['btnNode.btn2'].setVisible(false);
        for (var i = 0; i < btnList.length; i++) {
            //父节点的高度-1/2子节点的高度
            this._nodeList['btnNode.' + btnList[i]].y = 635 - 84 / 2 - 84 * i;
        }
    },


    _changeTab: function (tab) {
        if (this._currentSelectTab == tab) return;
        ClubDataManager.ClubStatisticsLayerSelectTab = tab;
        this._currentSelectTab = tab;
        var viewTab = null;

        for (var i = 0; i <= 5; i++) {
            var select = (i == this._currentSelectTab);
            var viewTabTemp = this._nodeList['btnNode.btn' + i].viewTab;
            if (select) {
                viewTab = viewTabTemp;
            }
            if (this[viewTabTemp] && cc.sys.isObjectValid(this[viewTabTemp])) {
                this[viewTabTemp].setVisible(false);
            }
            this._nodeList['btnNode.btn' + i + '.select'].setVisible(select);
            this._nodeList['btnNode.btn' + i + '.unselect'].setVisible(!select);
        }

        var tabLayer = this[viewTab];
        if (!tabLayer || !cc.sys.isObjectValid(tabLayer)) {
            this[viewTab] = addItem(viewTab, this._nodeList['viewNode'], this._clubId);
            tabLayer = this[viewTab];
        }
        if (!tabLayer || !cc.sys.isObjectValid(tabLayer)) return;
        tabLayer.setVisible(true);
        if (tabLayer['refreshView']) {
            var flag01 = false;
            if (this._currentSelectTab == 4) flag01 = true;
            else if (this._currentSelectTab == 5) flag01 = false;
            tabLayer.refreshView(flag01);
        }
    },
    _clickClose: function () {
        this.close();
        ClubDataManager.ClubStatisticsLayerSelectTab = 0;
        if (gameData.RoomStateIsReplay) {
            ClubViewUtil.openClubTableWindow(this._clubId);
        }
    },
    // close: function () {
    //     View.prototype.close.call(this);
    // },
});